package entityMapping.demo1;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Id;
import java.io.Serializable;

@Embeddable
class CompositeKey implements Serializable {
    private String key1;
    private String key2;

    @Id
    @Column(name = "KEY1")
    public String getKey1() {
        return key1;
    }

    public void setKey1(String key1) {
        this.key1 = key1;
    }

    @Column(name = "KEY2")
    public String getKey2() {
        return key2;
    }

    public void setKey2(String key2) {
        this.key2 = key2;
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 7 * result + (key1 == null ? 0 : key1.hashCode());
        result = 7 * result + (key2 == null ? 0 : key2.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof CompositeKey) {
            CompositeKey key = (CompositeKey) obj;
            return this.key1.equals(key.key1)
                    && this.key2.equals(key.key2);
        }
        return false;
    }

    @Override
    public String toString() {
        return "CompositeKey{" +
                "key1='" + key1 + '\'' +
                ", key2='" + key2 + '\'' +
                '}';
    }
}